import subprocess
import argparse

parser = argparse.ArgumentParser();
parser.add_argument('pdb', type=str, help='PDF file to operate on');
parser.add_argument('-v', action='store_true', dest='valgrind', default=False, help='Valgrind in case of a bad output');
parser.add_argument('-c', action='store_true', dest='clean', default=False, help='Fresh make');

args = parser.parse_args();

if args.clean:
    subprocess.call(['make', '-C', 'src', 'clean'])
    a = subprocess.call(['make', '-C', 'src']); 
    if a:
        exit(a)

if subprocess.call(['bin/main',"pdbs/"+args.pdb+".pdb"]) and args.valgrind:
    subprocess.call(['valgrind', 'bin/main', "pdbs/"+args.pdb+".pdb"])
